package com.ssm.helong.shop.controller;


import com.ssm.helong.shop.service.UserService;
import com.ssm.helong.shop.util.RedisUtils;
import com.ssm.helong.shop.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.UUID;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    RedisUtils redisUtils = RedisUtils.getRedisUtil();

    @PostMapping("login")
    public Result  login(String userLoginName, String userLoginPassword){
       String user = userService.login(userLoginName,userLoginPassword);
       if(user!=null){
           String token= UUID.randomUUID().toString().replace("-","").toLowerCase();
           redisUtils.set(token,user);
           return  new Result(token,"成功");
       }
       return  new Result("失败","000");
    }

    public static void main(String[] args) {
        RedisUtils redisUtils = RedisUtils.getRedisUtil();
        redisUtils.set("1","22");
        System.out.println(redisUtils.get("1"));
    }


}
